package com.fly.core.config.spring;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.RestController;

import com.fly.core.config.SwaggerConfig;

/**
 * 
 * 取代applicationContext.xml
 * 
 * @author 00fly
 * @version [版本号, 2023年4月21日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Configuration
@EnableScheduling
@EnableAspectJAutoProxy
@EnableTransactionManagement
@ComponentScan(basePackages = "com.fly", useDefaultFilters = true, excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class, RestController.class, ControllerAdvice.class}),
    @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = SwaggerConfig.class)})
public class ApplicationConfiguration
{
    @Autowired
    DataSource dataSource;
    
    /**
     * 设置事务管理器
     * 
     * @return
     */
    @Bean
    public PlatformTransactionManager platformTransactionManager()
    {
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }
}
